# 作者： 迷路的小怪兽
# 创建时间： 2024/3/25 23:35
from mitmproxy import http


class Filter:

    def __init__(self, domain='', method='ALL'):
        self.domain = domain if domain.startswith('http') else 'https://' + domain
        self.method_list = []
        if method == 'ALL':
            self.method_list.append('GET')
            self.method_list.append('POST')
        else:
            self.method_list.append(method)


    def is_target(self, flow: http.HTTPFlow):
        if flow.request.url.startswith(self.domain) and \
                flow.request.method in self.method_list:
            return True
        else:
            return False
